home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / skindow.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  6KB  |  137 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. import util
  6. from gui import skin, MultiImage
  7. from gui.toolbox import rect_with_negatives
  8.  
  9. class Skindow(wx.Frame):
  10.     framestyles = {
  11.         True: wx.FRAME_SHAPED | wx.SIMPLE_BORDER,
  12.         False: wx.DEFAULT_FRAME_STYLE }
  13.     
  14.     def __init__(self, parent, name, content_panel = None, use_skin = True, **kws):
  15.         if parent is not None and not isinstance(parent, wx.Window):
  16.             raise TypeError('first argument to Skindow __init__ is a wxWindow parent')
  17.         
  18.         wx.Frame.__init__(self, parent, style = self.framestyles[use_skin], **kws)
  19.         self.margins = skin.get('%s.content' % name)
  20.         self.content_pane = wx.Panel(self)
  21.         self.sizer = wx.BoxSizer()
  22.         self.content_pane.SetSizer(self.sizer)
  23.         if not isinstance(name, (str, unicode)):
  24.             raise TypeError('second argument name must be a string')
  25.         
  26.         self.name = name
  27.         self.skin_events = [
  28.             (wx.EVT_SIZE, self.on_size),
  29.             (wx.EVT_PAINT, self.on_paint),
  30.             (wx.EVT_LEFT_UP, self.OnLeftUp),
  31.             (wx.EVT_LEFT_DOWN, self.on_left_down),
  32.             (wx.EVT_MOTION, self.on_motion),
  33.             (wx.EVT_ERASE_BACKGROUND, (lambda e: pass))]
  34.         self.Bind((wx.EVT_CLOSE,), (lambda e: self.Destroy()))
  35.         self.set_skinned(use_skin)
  36.  
  37.     
  38.     def set_skinned(self, skinned = True):
  39.         self.SetWindowStyleFlag(self.framestyles[skinned])
  40.         self.Refresh()
  41.  
  42.     
  43.     def get_skinned(self):
  44.         return self.GetWindowStyleFlag() == self.framestyles[True]
  45.  
  46.     skinned = property(get_skinned, set_skinned)
  47.     
  48.     def set_content(self, content):
  49.         self.Refresh()
  50.  
  51.     
  52.     def on_size(self, e = None):
  53.         m = rect_with_negatives(self.margins, self.GetSize())
  54.         self.content_pane.SetPosition(m[:2])
  55.         self.content_pane.SetSize(m[2:])
  56.         if e:
  57.             e.Skip(True)
  58.         
  59.  
  60.     
  61.     def on_paint(self, e = None):
  62.         dc = wx.BufferedPaintDC(self)
  63.         self.multi.Draw(dc, wx.Rect(0, 0, *self.GetClientSizeTuple()))
  64.         self.SetShape(self.multi.region)
  65.  
  66.     
  67.     def SetWindowShape(self, *evt):
  68.         new = (w, h) = self.GetClientSizeTuple()
  69.         if hasattr(self.multi, 'region'):
  70.             print '%r has a region: %r' % (self.multi, self.multi.region)
  71.             self.hasShape = self.SetShape(self.multi.region)
  72.         
  73.  
  74.     
  75.     def on_left_down(self, evt):
  76.         self.CaptureMouse()
  77.         if 'dragger' in self.multi and wx.Rect(*self.multi.tag_rect('dragger')).Contains(evt.GetPosition()):
  78.             self.orig = self.ClientToScreen(evt.GetPosition())
  79.             self.origsize = self.GetSize()
  80.             self.click_state = 'resizing'
  81.         else:
  82.             self.click_state = 'moving'
  83.             (x, y) = self.ClientToScreen(evt.GetPosition())
  84.             (originx, originy) = self.GetPosition()
  85.             self.delta = (x - originx, y - originy)
  86.  
  87.     
  88.     def OnLeftUp(self, evt):
  89.         self.on_size()
  90.         if self.HasCapture():
  91.             self.ReleaseMouse()
  92.         
  93.  
  94.     
  95.     def on_motion(self, evt):
  96.         if 'dragger' in self.multi.tags:
  97.             if wx.Rect(*self.multi.tag_rect('dragger')).Contains(evt.GetPosition()):
  98.                 self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENWSE))
  99.             else:
  100.                 self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
  101.         
  102.         if evt.Dragging() and evt.LeftIsDown():
  103.             (x, y) = self.ClientToScreen(evt.GetPosition())
  104.             if self.click_state == 'resizing':
  105.                 self.method_sizing()
  106.                 if not self.sizing:
  107.                     self.sizing = True
  108.                     dx = x - self.orig[0]
  109.                     dy = y - self.orig[1]
  110.                     self.SetSize((self.origsize[0] + dx, self.origsize[1] + dy))
  111.                     self.sizing = False
  112.                 
  113.             elif self.click_state == 'moving':
  114.                 fp = (x - self.delta[0], y - self.delta[1])
  115.                 self.Move(fp)
  116.             
  117.         
  118.  
  119.     
  120.     def method_sizing(self):
  121.         pass
  122.  
  123.  
  124. if __name__ == '__main__':
  125.     import util
  126.     import windowfx
  127.     app = wx.PySimpleApp()
  128.     from gui import skininit
  129.     skininit('../../res', 'halloween')
  130.     frame = Skindow(None, 'IMWin', title = 'Skindow Test')
  131.     from uberwidgets.UberBook import SamplePanel
  132.     frame.set_content(SamplePanel(frame.content, 'orange'))
  133.     windowfx.fadein(frame)
  134.     app.SetTopWindow(frame)
  135.     util.profile(app.MainLoop)
  136.  
  137.